//
// Created by 11510 on 2024/7/11.
//
#include "EventFd.h"
#include <unistd.h>
#include <thread>
#include <iostream>

using std::cout;
using std::endl;
using std::thread;

class MyTask {
public:
    void process() {
        cout << "MyTask is running" << endl;
    }
};


int main(int argc, char *argv[]) {
    MyTask task;
    EventFd efd(std::bind(&MyTask::process, &task));
    thread th(std::bind(&EventFd::start, &efd));

    int cnt = 10;
    while (cnt--) {
        efd.wakeup();
        /**
         * 主线程执行的太快，来不及wakeup()有可能就结束了，所以要sleep()一下
         */
        sleep(1);
    }

    efd.stop();
    th.join();
    return 0;
}